gtk-demo: Add a shader paintable to the fishbowl
authorAlexander Larsson <alexl@redhat.com>
Tue, 29 Sep 2020 07:36:10 +0000 (09:36 +0200)
committerAlexander Larsson <alexl@redhat.com>
Tue, 29 Sep 2020 07:51:16 +0000 (09:51 +0200)
This gets around 500 instances at 60fps on my system.

demos/gtk-demo/fishbowl.c

index 40c8203726c0665fb766cc44de9a9ca2a340fc21..659318b7cdcd28574151e4e29d282b1a3c4ae9e9 100644 (file)
@@ -9,6 +9,7 @@
 
 #include "gtkfishbowl.h"
 #include "gtkgears.h"
+#include "gskshaderpaintable.h"
 
 const char *const css =
 ".blurred-button {"
@@ -149,6 +150,38 @@ create_switch (void)
   return w;
 }
 
+static gboolean
+update_paintable (GtkWidget     *widget,
+                  GdkFrameClock *frame_clock,
+                  gpointer       user_data)
+{
+  GskShaderPaintable *paintable;
+  gint64 frame_time;
+
+  paintable = GSK_SHADER_PAINTABLE (gtk_picture_get_paintable (GTK_PICTURE (widget)));
+  frame_time = gdk_frame_clock_get_frame_time (frame_clock);
+  gsk_shader_paintable_update_time (paintable, 0, frame_time);
+
+  return G_SOURCE_CONTINUE;
+}
+
+static GtkWidget *
+create_cogs (void)
+{
+  GtkWidget *picture;
+  static GskGLShader *cog_shader = NULL;
+  GdkPaintable *paintable;
+
+ if (cog_shader == NULL)
+    cog_shader = gsk_gl_shader_new_from_resource ("/gltransition/cogs2.glsl");
+  paintable = gsk_shader_paintable_new (g_object_ref (cog_shader), NULL);
+  picture = gtk_picture_new_for_paintable (paintable);
+  gtk_widget_set_size_request (picture, 150, 75);
+  gtk_widget_add_tick_callback (picture, update_paintable, NULL, NULL);
+
+  return picture;
+}
+
 static void
 mapped (GtkWidget *w)
 {
@@ -185,6 +218,7 @@ static const struct {
   { "Gears",      create_gears          },
   { "Switch",     create_switch         },
   { "Menubutton", create_menu_button    },
+  { "Shader",     create_cogs           },
 };
 
 static int selected_widget_type = -1;